package com.example.employee.validation;

import jakarta.validation.ConstraintValidator;
import jakarta.validation.ConstraintValidatorContext;

import java.time.LocalDateTime;

public class CustomValidator implements ConstraintValidator<CustomValidation, LocalDateTime> {

    private String rule;

    @Override
    public void initialize(CustomValidation constraintAnnotation) {
        this.rule = constraintAnnotation.rule();
    }

    @Override
    public boolean isValid(LocalDateTime endTime, ConstraintValidatorContext context) {
        if (!"endAfterStart".equals(rule)) {
            return true; // 不处理其他规则
        }

        // 假设我们能获取到 startTime，这里仅示意逻辑，实际应通过对象整体校验
        // 更合理的做法是将注解放在类上，并传入相关字段名进行比较
        return true;
    }
}
